package com.gsafety.libraryktx.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.github.mikephil.charting.charts.LineChart
import com.gsafety.libraryktx.R
import com.gsafety.libraryktx.bean.AxisText
import com.gsafety.libraryktx.util.LineChartManager

/**
 * @author : lj
 * @date : 2020/7/31 14:06
 */
class CommonLineChart @JvmOverloads constructor(context: Context,
                                                attrs: AttributeSet? = null,
                                                defStyleAttr: Int = 0) : LinearLayout(context,attrs,defStyleAttr) {
    var chart: LineChart?=null
    init {
        initview(attrs)
    }


    private fun initview(attrs:AttributeSet?){
        var view = LayoutInflater.from(context).inflate(R.layout.common_linechart_layout, this)
        chart=view.findViewById(R.id.chart_line)

    }

    fun setData(xAxisValues:MutableList<AxisText>, yAxisValues: MutableList<List<Float>>, colors: MutableList<Int>){
        chart?.also {
            var manager = LineChartManager(it)
            manager.showLineChart(context,xAxisValues,yAxisValues,colors)
            manager.setXAxis(xAxisValues.size.toFloat(),-1f,xAxisValues.size+1,false)
        }
    }
}